package com.jgame.secondarymarket.interfaces.assembler.product;

import cn.hutool.core.bean.BeanUtil;
import com.jgame.secondarymarket.domain.product.entity.ProductProperties;
import com.jgame.secondarymarket.interfaces.dto.product.ProductPropertiesDTO;
import com.jgame.secondarymarket.interfaces.vo.product.ProductPropertiesVO;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 商品属性领域对象与DTO转换
 *
 * @title: ProductPropertiesAssembler
 * @Author Wangsj
 * @Date: 2021/7/23
 */
public class ProductPropertiesAssembler {

    public static List<ProductProperties> toProductProperties(List<ProductPropertiesDTO> dtos) {
        return dtos.stream().map(dto -> {
            ProductProperties productProperties = new ProductProperties();
            BeanUtil.copyProperties(dto, productProperties);
            return productProperties;
        }).collect(Collectors.toList());
    }


    public static Map<String, List<ProductPropertiesVO>> toVO(List<ProductProperties> properties) {
        List<ProductPropertiesVO> productPropertiesVOS = properties.stream()
                .map(p -> {
                    ProductPropertiesVO productPropertiesVO = new ProductPropertiesVO();
                    BeanUtil.copyProperties(p, productPropertiesVO);
                    return productPropertiesVO;
                }).collect(Collectors.toList());

        return productPropertiesVOS.stream().collect(Collectors.groupingBy(ProductPropertiesVO::getTage));
    }
}
